﻿using System;
using System.Text.RegularExpressions;
using Autodesk.Revit.DB;

namespace YJKInspectModel.ModelValidation.FireCompartment
{
	internal class UtilityTools
	{
		public static bool IsValidFireDoor(FamilyInstance fi)
		{
			try
			{
				if (Regex.IsMatch(fi.Symbol.Family.Name, "防火|FM|fm|FJM|fjm|FC|fc"))
				{
					return true;
				}
				if (Regex.IsMatch(fi.Symbol.Name, "FM|fm|FJM|fjm|FC|fc"))
				{
					return true;
				}
			}
			catch
			{
			}
			return false;
		}

		public static bool IsValidFlipFacingFireDoor(FamilyInstance fi)
		{
			try
			{
				if (UtilityTools.IsValidFireDoor(fi))
				{
					return fi.CanFlipFacing;
				}
			}
			catch
			{
			}
			return false;
		}

		public static bool IsValid3HourFireWall(Element elemWall)
		{
			try
			{
				Wall wall = elemWall as Wall;
				if (Regex.IsMatch(wall.WallType.Name, "防火"))
				{
					return Regex.IsMatch(wall.WallType.get_Parameter(BuiltInParameter.DOOR_FIRE_RATING).AsString(), "3小时|3h|3H");
				}
			}
			catch
			{
			}
			return false;
		}

		public static bool IsValidFireDoorWinFamilyName(string strFamilyName)
		{
			return Regex.IsMatch(strFamilyName, "防火|FM|fm|FJM|fjm|FC|fc");
		}

		public static bool IsValidDoorWinFamilySymbolName(string strFamilyName)
		{
			return Regex.IsMatch(strFamilyName, "FM|fm|FJM|fjm|FC|fc");
		}

		public static bool IsValidDoorWinClassAFamilyName(string strFamilyName)
		{
			return UtilityTools.IsValidFireDoorWinFamilyName(strFamilyName) && !Regex.IsMatch(strFamilyName, "乙|丙");
		}

		public static bool IsValidDoorRollingFamilyName(string strFamilyName)
		{
			return UtilityTools.IsValidFireDoorWinFamilyName(strFamilyName) && Regex.IsMatch(strFamilyName, "卷帘");
		}

		public static bool IsValidDoorWinClassAFamilyName(string strFamilyName, string strSymbolName)
		{
			return (UtilityTools.IsValidFireDoorWinFamilyName(strFamilyName) && !Regex.IsMatch(strFamilyName, "乙|丙") && !Regex.IsMatch(strSymbolName, "乙|丙")) || (UtilityTools.IsValidFireDoorWinFamilyName(strSymbolName) && !Regex.IsMatch(strFamilyName, "乙|丙") && !Regex.IsMatch(strSymbolName, "乙|丙"));
		}

		public static bool IsValidDoorRollingSuperFamilyName(string strFamilyName, string strSymbolName)
		{
			return UtilityTools.IsValidDoorWinClassAFamilyName(strFamilyName, strSymbolName) && (Regex.IsMatch(strFamilyName, "特级") || Regex.IsMatch(strSymbolName, "特级"));
		}
	}
}
